package org.mentalsmash.tazio.evaluation.tests;

import java.lang.management.ManagementFactory;

import javax.management.JMException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import com.google.common.base.Preconditions;

public class TestData implements TestDataMBean {

    private volatile boolean finished = false;

    private volatile long duration = -1;

    public boolean isFinished() {
	return this.finished;
    }

    public long getDuration() {
	return this.duration;
    }

    public void setFinished() {
	this.finished = true;
    }

    protected void setDuration(long duration) {
	Preconditions.checkArgument(duration > 0);
	this.duration = duration;
    }

    public void register() {
	ObjectName name;
	try {
	    name = new ObjectName(
		    "org.mentalsmash.tazio.evaluation:type=TestData");

	    ManagementFactory.getPlatformMBeanServer()
		    .registerMBean(this, name);

	} catch (MalformedObjectNameException e) {
	    e.printStackTrace();
	} catch (NullPointerException e) {
	    e.printStackTrace();
	} catch (JMException e) {
	    e.printStackTrace();
	} 
    }
}
